/* ** por compatibilidad se omiten tildes **
================================================================================
 TRABAJO PRACTICO 3 - System Programming - ORGANIZACION DE COMPUTADOR II - FCEN
================================================================================
  definicion de funciones del scheduler
*/

#include "screen.h"
#include "colors.h"

unsigned short* video = (unsigned short*) 0xb8000;
char* reg[] = {"eax", "ebx", "ecx", "edx", "esi", "edi", "ebp", "esp", "eip",
		      " cs", " ds", " es", " fs", " gs", " ss", " eflags"};

char* creg[] = {"cr0", "cr2", "cr3", "cr4"};

char* stack[] = {"stack"};

char* tanque[] = {"Tanque"};

void pintar_pantalla(){
	pintar(0x20, 50, 50, 0, 0);
	pintar(0x00, 30, 50, 50, 0);
	pintar(0x40, 80-52, 1, 52, 3);
	pintar(0x40, 80-52, 42-39, 52, 39);
	pintar(0x70, 80-52, 38-4, 52, 4);
	pintar(0x70, 70-53, 50-47, 53, 47);
	imprimir_registros(reg, 0x70, 5, 53, 16);
	imprimir_registros(creg, 0x70, 5, 67, 4);
	imprimir_registros(stack, 0x70, 22, 67, 1);
	imprimir_registros(tanque, 0x4F, 3, 53, 1);
}

void pintar(unsigned short color, unsigned short tamx, unsigned short tamy, unsigned short offsetx, unsigned short offsety){
	unsigned int i = 0;
	unsigned int j = 0;
	for(i = offsety; i < tamy + offsety; i++){
		for(j = offsetx; j < tamx + offsetx; j++){
			*(video + 80*i + j) = color << 8;
		}
	}
}

void imprimir_registros(char** registros, unsigned short color, unsigned int fila, unsigned int columna, unsigned int cant_elementos){
	unsigned int i;
	unsigned int columna_aux = columna;
	for(i = 0; i < cant_elementos; i++){
		escribir(registros[i], color, fila, columna_aux);
		columna_aux = columna;
		fila +=2;
	}
}

void escribir(char* texto, unsigned short color, unsigned int fila, unsigned int columna){
	unsigned int j;
	for(j = 0; *(texto + j)!= 0; j++){
		unsigned short letra = (unsigned short)*(texto + j);
		letra += (color << 8);
		*(video + 80*fila + columna) = letra;
		columna++;
	}
}

void escribir_numero(unsigned short color, unsigned int fila, unsigned int columna){
//	unsigned int j;
//	for(j = 0; *(texto + j)!= 0; j++){
//		unsigned short letra = (unsigned short)*(texto + j);
//		letra += (color << 8);
		*(video + 80*fila + columna) = color;
//		columna++;
//	}
}

void escribir_posicion(short color, unsigned int fila, unsigned int columna){
//	unsigned int j;
//	for(j = 0; *(texto + j)!= 0; j++){
//		unsigned short letra = (unsigned short)*(texto + j);
//		letra += (color << 8);
		*(video + 80*fila + columna +1) = color;
//		columna++;
//	}
}
